package com.warm.demo.mf.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.warm.core.domain.R;
import com.warm.demo.mf.api.dto.TestLeaveDto;
import com.warm.demo.mf.api.vo.TestLeaveVo;
import com.warm.demo.mf.service.ITestLeaveService;
import com.warm.log.annotation.Log;
import com.warm.log.enums.BusinessType;
import com.warm.mf.core.domain.QueryParam;
import com.warm.mf.core.page.TableDataInfo;
import com.warm.mybatis.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.noear.solon.annotation.*;
import org.noear.solon.validation.annotation.Valid;

/**
 * OA 请假申请Controller
 *
 * @author warm
 */
@Api(value = "OA 请假申请控制器", tags = {"OA 请假申请管理"})
@Valid
@Controller
@Mapping("/test/leave")
public class TestLeaveController extends BaseController {
    @Inject
    private ITestLeaveService testLeaveService;

    /**
     * 分页查询OA 请假申请列表
     */
    @ApiOperation("分页查询OA 请假申请列表")
    @SaCheckPermission("test:leave:list")
    @Get
    @Mapping("/list")
    public TableDataInfo<TestLeaveVo> list(QueryParam queryParam, TestLeaveDto dto) {
        return testLeaveService.selectPage(queryParam, dto);
    }


    /**
     * 获取OA 请假申请详细信息
     */
    @ApiOperation("获取OA 请假申请详细信息")
    @SaCheckPermission("test:leave:query")
    @Get
    @Mapping(value = "/{id}")
    public R<TestLeaveVo> getInfo(Long id) {
        return R.ok(testLeaveService.selectById(id));
    }

    /**
     * 新增OA 请假申请
     */
    @ApiOperation("新增OA 请假申请")
    @SaCheckPermission("test:leave:add")
    @Log(title = "OA 请假申请", businessType = BusinessType.INSERT)
    @Post
    @Mapping
    public R<Void> add(TestLeaveDto dto) {
        return toR(testLeaveService.insertByDto(dto));
    }

    /**
     * 修改OA 请假申请
     */
    @ApiOperation("修改OA 请假申请")
    @SaCheckPermission("test:leave:edit")
    @Log(title = "OA 请假申请", businessType = BusinessType.UPDATE)
    @Put
    @Mapping
    public R<Void> edit(TestLeaveDto dto) {
        return toR(testLeaveService.updateByDto(dto));
    }

    /**
     * 删除OA 请假申请
     */
    @ApiOperation("删除OA 请假申请")
    @SaCheckPermission("test:leave:remove")
    @Log(title = "OA 请假申请", businessType = BusinessType.DELETE)
    @Delete
    @Mapping("/{ids}")
    public R<Void> remove(Long[] ids) {
        return toR(testLeaveService.deleteByIds(ids));
    }
}
